package com.cz.nongyetongv5.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.activity.EntDetailActivity;


/**
 * 我的页面
 * Created by zhangliang on 2017/6/26.
 */

public class EntInfoBaseFragment extends Fragment {

    private TextView tv_area;
    private TextView tv_ent;
    private TextView tv_ent_name;
    private TextView tv_charge;
    private TextView tv_idcard;
    private TextView tv_sex;
    private TextView tv_edu;
    private TextView tv_tel;
    private TextView tv_phone;

    private ImageView iv_tel;
    private ImageView iv_sms;
    private ImageView iv_mobile;


    private View view;


    public static EntInfoBaseFragment newInstance() {
        EntInfoBaseFragment fragment = new EntInfoBaseFragment();
        return fragment;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_ent_info_base, null);
        tv_area = view.findViewById(R.id.tv_area);
        tv_ent = view.findViewById(R.id.tv_ent);
        tv_ent_name = view.findViewById(R.id.tv_ent_name);
        tv_charge = view.findViewById(R.id.tv_charge);
        tv_idcard = view.findViewById(R.id.tv_idcard);
        tv_sex = view.findViewById(R.id.tv_sex);
        tv_edu = view.findViewById(R.id.tv_edu);
        tv_tel = view.findViewById(R.id.tv_tel);
        tv_phone = view.findViewById(R.id.tv_phone);
        iv_tel = view.findViewById(R.id.iv_tel);
        iv_sms = view.findViewById(R.id.iv_sms);
        iv_mobile = view.findViewById(R.id.iv_mobile);
        iv_mobile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + ((EntDetailActivity) getActivity()).getEntBean().getMobile()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });
        iv_tel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + ((EntDetailActivity) getActivity()).getEntBean().getTel()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });
        iv_sms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri uri2 = Uri.parse("smsto:" + ((EntDetailActivity) getActivity()).getEntBean().getMobile());
                Intent intentMessage = new Intent(Intent.ACTION_VIEW, uri2);
                startActivity(intentMessage);
            }
        });
        init();
        return view;
    }


    public void init() {
        if (((EntDetailActivity) getActivity()).getEntBean().getRegion_name() != null && !((EntDetailActivity) getActivity()).getEntBean().getRegion_name().isEmpty()) {
            tv_area.setText(((EntDetailActivity) getActivity()).getEntBean().getRegion_name());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getKind_name() != null && !((EntDetailActivity) getActivity()).getEntBean().getKind_name().isEmpty()) {
            tv_ent.setText(((EntDetailActivity) getActivity()).getEntBean().getKind_name());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getName() != null && !((EntDetailActivity) getActivity()).getEntBean().getName().isEmpty()) {
            tv_ent_name.setText(((EntDetailActivity) getActivity()).getEntBean().getName());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getCharge() != null && !((EntDetailActivity) getActivity()).getEntBean().getCharge().isEmpty()) {
            tv_charge.setText(((EntDetailActivity) getActivity()).getEntBean().getCharge());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getIdcard() != null && !((EntDetailActivity) getActivity()).getEntBean().getIdcard().isEmpty()) {
            tv_idcard.setText(((EntDetailActivity) getActivity()).getEntBean().getIdcard());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getSex_name() != null && !((EntDetailActivity) getActivity()).getEntBean().getSex_name().isEmpty()) {
            tv_sex.setText(((EntDetailActivity) getActivity()).getEntBean().getSex_name());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getEducation_name() != null && !((EntDetailActivity) getActivity()).getEntBean().getEducation_name().isEmpty()) {
            tv_edu.setText(((EntDetailActivity) getActivity()).getEntBean().getEducation_name());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getTel() != null && !((EntDetailActivity) getActivity()).getEntBean().getTel().isEmpty()) {
            tv_tel.setText(((EntDetailActivity) getActivity()).getEntBean().getTel());
        } else {
            iv_tel.setVisibility(View.GONE);
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getMobile() != null && !((EntDetailActivity) getActivity()).getEntBean().getMobile().isEmpty()) {
            tv_phone.setText(((EntDetailActivity) getActivity()).getEntBean().getMobile());
        } else {
            iv_mobile.setVisibility(View.GONE);
            iv_sms.setVisibility(View.GONE);
        }
    }
}